package com.gaogzhen.designPattern.producerConsumer;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j(topic = "c.MessageQueueTest01")
public class MessageQueueTest01 {
    public static void main(String[] args) throws InterruptedException {
        // 创建消息队列，初始容量2
        MessageQueue queue = new MessageQueue(2);
        // 模拟3个生产者线程
        for (int i = 0; i < 3; i++) {

            int id = i;
            new Thread(() -> {
                queue.putMessage(new Message(id, "啦啦啦啦" + id));
            }, "生产者" + i).start();
        }

        // 等待1s
        TimeUnit.SECONDS.sleep(1);

        // 模拟1个消费者线程
        new Thread(() -> {
            while (true) {
                Message message = queue.getMessage();
            }
        }, "消费者").start();

    }
}
